package longmethod;

import lombok.Getter;

@Getter
public class MethodTooLong {

    private int size;
    private Object[] elements;
    private boolean readOnly;

    public MethodTooLong(int length, boolean readOnly) {
        this.elements = new Object[length];
        this.readOnly = readOnly;
        this.size = 0;
    }

    public void add(Object element) {
        if (!readOnly) {
            int newSize = size + 1;
            if (newSize > elements.length) {
                Object[] newElements = new Object[elements.length + 10];
                for (int i = 0; i < size; i++) {
                    newElements[i] = elements[i];
                }
                elements = newElements;
            }
            elements[size++] = element;
        }
    }

}
